package com.jindy.module.oaContractApply.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.jindy.module.oaEvectionApproval.controller.SyOaEvectionController;
import com.jindy.module.oaEvectionApproval.domain.SyOaEvection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.jindy.common.annotation.Log;
import com.jindy.common.core.controller.BaseController;
import com.jindy.common.core.domain.AjaxResult;
import com.jindy.common.enums.BusinessType;
import com.jindy.module.oaContractApply.domain.SyOaContract;
import com.jindy.module.oaContractApply.service.ISyOaContractService;
import com.jindy.common.utils.poi.ExcelUtil;
import com.jindy.common.core.page.TableDataInfo;

/**
 * 智能合同审批Controller
 * 
 * @author jindy
 * @date 2023-06-29
 */
@RestController
@RequestMapping("/module/SyOaContract")
public class SyOaContractController extends BaseController
{
    private static final Logger LOGGER = LoggerFactory.getLogger(SyOaContractController.class);

    @Autowired
    private ISyOaContractService syOaContractService;

    /**
     * 查询智能合同审批列表
     */
    @PreAuthorize("@ss.hasPermi('module:SyOaContract:list')")
    @GetMapping("/list")
    public TableDataInfo list(SyOaContract syOaContract)
    {
        startPage();
        List<SyOaContract> list = syOaContractService.selectSyOaContractList(syOaContract);
        return getDataTable(list);
    }

    /**
     * 导出智能合同审批列表
     */
    @PreAuthorize("@ss.hasPermi('module:SyOaContract:export')")
    @Log(title = "智能合同审批", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SyOaContract syOaContract)
    {
        List<SyOaContract> list = syOaContractService.selectSyOaContractList(syOaContract);
        ExcelUtil<SyOaContract> util = new ExcelUtil<SyOaContract>(SyOaContract.class);
        util.exportExcel(response, list, "智能合同审批数据");
    }

    /**
     * 获取智能合同审批详细信息
     */
    @PreAuthorize("@ss.hasPermi('module:SyOaContract:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(syOaContractService.selectSyOaContractById(id));
    }

    /**
     * 新增智能合同审批
     */
    @PreAuthorize("@ss.hasPermi('module:SyOaContract:add')")
    @Log(title = "智能合同审批", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SyOaContract syOaContract)
    {
        return toAjax(syOaContractService.insertSyOaContract(syOaContract));
    }

    /**
     * 修改智能合同审批
     */
    @PreAuthorize("@ss.hasPermi('module:SyOaContract:edit')")
    @Log(title = "智能合同审批", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SyOaContract syOaContract)
    {
        return toAjax(syOaContractService.updateSyOaContract(syOaContract));
    }

    /**
     * 删除智能合同审批
     */
    @PreAuthorize("@ss.hasPermi('module:SyOaContract:remove')")
    @Log(title = "智能合同审批", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(syOaContractService.deleteSyOaContractByIds(ids));
    }

    /**
     * 提交申请
     */
    @Log(title = "智能合同审批", businessType = BusinessType.UPDATE)
    @PostMapping( "/submitApply/{id}")
    @ResponseBody
    public AjaxResult submitApply(@PathVariable Long id) {
        try {
            SyOaContract syOaContract = syOaContractService.selectSyOaContractById(id);
            syOaContractService.submitApply(syOaContract);
        } catch (Exception e) {
            LOGGER.error("智能合同审批提交申请出错",e);
            return error("智能合同审批提交申请出错：" + e.getMessage());
        }
        return success();
    }
}
